//
// Created by 25313 on 2025/8/5.
//
class Solution {
public:
    long long pickGifts(vector<int>& gifts, int k) {
        long long res = 0;
        int size = gifts.size();
        int t = size - 1;
        for(int i = 0; i < k; i++)
        {
            if(size == 1 && gifts[t] > 1)
            {
                gifts[t] = sqrt(gifts[t]);
            }
            else if(size > 1)
            {
                sort(gifts.begin(),gifts.end());
                gifts[t] = sqrt(gifts[t]);
            }
        }
        for(int num : gifts)
        {
            res += num;
        }
        return res;
    }
};